/***********************************************************************
    filename:   DaterTplEventFactory.h
    created:    10/4/2012
    author:     4Ys
*************************************************************************/
#ifndef _DaterTplEventFactory_h_
#define _DaterTplEventFactory_h_

#include "DaterEventFactory.h"

namespace Dater
{
	/*!
	\brief
		Template based EventFactory that can be used to automatically generate a
		EventFactory given a Event based class.

		The advantage of this over the previous macro based methods is that there is
		no longer any need to have any supporting code or structure in order to add
		new Window types to the system, rather you can just do:
		\code
		Dater::EventFactoryManager::addFactory<TplEventFactory<MyEventType> >();
		\endcode

	\tparam T
		Specifies the Event based class that the factory will create and
		destroy instances of.
	*/
	template <typename T>
	class TplEventFactory : public EventFactory
	{
	public:
		//! Default constructor
		TplEventFactory();

		// Implement EventFactory interface
		Event* createEvent(const std::string& name,const Time& startTime, 
			const Time& finishTime, const std::string& description, int userID, long uid);
		void destoryEvent(Event* theEvent);
	};

	//----------------------------------------------------------------------------//
	template <typename T>
	TplEventFactory<T>::TplEventFactory() : EventFactory(T::EventTypeName)
	{
	}

	//----------------------------------------------------------------------------//
	template <typename T>
	Event* TplEventFactory<T>::createEvent(const std::string& name,const Time& startTime, 
			const Time& finishTime, const std::string& description, int userID, long uid)
	{
		return new T(_type, name, startTime, finishTime, description, userID, uid);
	}

	//----------------------------------------------------------------------------//
	template <typename T>
	void TplEventFactory<T>::destoryEvent(Event* theEvent)
	{
		delete theEvent;
	}

	//----------------------------------------------------------------------------//
}

#endif